﻿using Chart3D;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FEM.Basic
{
    /// <summary>
    /// 单元拓展方法
    /// </summary>
    public static class ElementExtension
    {
        /// <summary>
        /// 获得单元绘制序列
        /// </summary>
        /// <param name="element"></param>
        /// <param name="nodeDict"></param>
        /// <returns></returns>
        public static DataSeries GetData(this FEMElement element, Dictionary<int, Node> nodeDict, bool isBlack)
        {
            //获得IJ节点
            var nodeI = nodeDict[element.I_Node_Index];
            var nodeJ = nodeDict[element.J_Node_Index];
            //数据点
            var prtI = new Point3D((float)nodeI.X, (float)nodeI.Y, (float)nodeI.Z);
            var prtJ = new Point3D((float)nodeJ.X, (float)nodeJ.Y, (float)nodeJ.Z);
            //获得数据点
            if (element is FEMBeam || element is FEMColumn || element is IsolationElement)
            {
                //构造曲线
                var data = new DataSeries(DrawType.Line, false);
                //添加数据点
                data.AddPoint(prtI); data.AddPoint(prtJ);
                //设定颜色
                if (element is FEMBeam)
                    data.SetLineStyle(isBlack ? Color.Yellow : Color.Red, SeriesStyle.PlotLinesMethodEnum.Lines);
                else if (element is FEMColumn)
                {
                    if (Math.Abs(prtI.X - prtJ.X) < 1 && Math.Abs(prtI.Y - prtJ.Y) < 1)
                        data.SetLineStyle(Color.Green, SeriesStyle.PlotLinesMethodEnum.Lines);
                    else data.SetLineStyle(Color.Purple, SeriesStyle.PlotLinesMethodEnum.Lines);
                }
                else data.SetLineStyle(Color.Purple, SeriesStyle.PlotLinesMethodEnum.Lines);
                //返回曲线
                return data;
            }
            else if (element is FEMShell)
            {
                //构造曲线
                var data = new DataSeries(DrawType.Surface, false);
                //转单元
                var shell = (FEMShell)element;
                //构造节点
                var nodeK = nodeDict[shell.K_Node_Index];
                var nodeL = nodeDict[shell.L_Node_Index];
                //数据点
                var prtK = new Point3D((float)nodeK.X, (float)nodeK.Y, (float)nodeK.Z);
                var prtL = new Point3D((float)nodeL.X, (float)nodeL.Y, (float)nodeL.Z);
                //构造数据点
                data.PointArray = new Point3D[2, 2];
                data.PointArray[0, 0] = prtI; data.PointArray[0, 1] = prtJ;
                data.PointArray[1, 0] = prtK; data.PointArray[1, 1] = prtL;
                //返回曲线
                return data;
            }
            return null;
        }
    }
}
